//
//  DsErErCell.m
//  Tour
//
//  Created by 张张烨 on 16/3/11.
//  Copyright © 2016年 张中烨. All rights reserved.
//

#import "DsErErCell.h"
#import "DsErErModel.h"
#import "PrefixHeader.pch"
#define kWidth [UIScreen mainScreen].bounds.size.width
#define kHeight [UIScreen mainScreen].bounds.size.height
#define kSelfWidth self.frame.size.width
#define kSelfHeight self.frame.size.height

@interface DsErErCell ()

@end
@implementation DsErErCell


- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    
    if (self) {
        
//        self.selectionStyle = UITableViewCellSeparatorStyleNone;
        
        self.clipsToBounds = YES;
        /**<  图片 */
        _picture = [[UIImageView alloc]initWithFrame:CGRectMake(0, -(kHeight/1.7 - (250 * GAO))/2, kWidth, kHeight/1.7)];
        
        _picture.contentMode = UIViewContentModeScaleAspectFill;
        [self.contentView  addSubview:_picture];
        /**<  view */
        _coverview = [[UIView alloc] initWithFrame:CGRectMake(0, 0, kWidth, 250 * GAO)];
//        _coverview.backgroundColor = [UIColor colorWithWhite:0 alpha:0.33];
        [self.contentView addSubview:_coverview];
        /**<  名字 */
        _titleLabel = [[UILabel alloc]initWithFrame:CGRectMake(0, (250 / 2 - 30) * GAO, kWidth, 30 * GAO)];
        
        _titleLabel.font = [UIFont boldSystemFontOfSize:16];
        
        _titleLabel.textAlignment = NSTextAlignmentCenter;
        
        _titleLabel.textColor = [UIColor whiteColor];
        
        [self.contentView addSubview:_titleLabel];
        /**<  时间 */
        _littleLabel = [[UILabel alloc]initWithFrame:CGRectMake(0, (250 / 2 + 30) *GAO, kWidth, 30 * GAO)];
        
        _littleLabel.font = [UIFont systemFontOfSize:14];
        
        _littleLabel.textAlignment = NSTextAlignmentCenter;
        
        _littleLabel.textColor = [UIColor whiteColor];
        
        [self.contentView addSubview:_littleLabel];
        
        
        
    }
    return self;
    
}


- (void)setModel:(DsErErModeler *)model{
    
    _model = model;
        
        [_picture sd_setImageWithURL:[NSURL URLWithString:_model.sanModel.siModel.detail]];
        
        _titleLabel.text = _model.sanModel.title;
        // 转换时间
        NSInteger time = [_model.sanModel.duration integerValue];
        
        NSString *timeString = [NSString stringWithFormat:@"%02ld'%02ld''",time/60,time% 60];//显示的是音乐的总时间
        
        NSString *string = [NSString stringWithFormat:@"#%@ / %@",_model.sanModel.category, timeString];
        
        _littleLabel.text = string;
    }
    


- (CGFloat)cellOffset {
    
    CGRect centerToWindow = [self convertRect:self.bounds toView:self.window];
    CGFloat centerY = CGRectGetMidY(centerToWindow);
    CGPoint windowCenter = self.superview.center;
    
    CGFloat cellOffsetY = centerY - windowCenter.y;
    
    CGFloat offsetDig =  cellOffsetY / self.superview.frame.size.height *2;
    CGFloat offset =  -offsetDig * (kHeight/1.7 - (250 * GAO))/2;
    
    CGAffineTransform transY = CGAffineTransformMakeTranslation(0,offset);
    
    //    self.titleLabel.transform = transY;
    //    self.littleLabel.transform = transY;
    
    self.picture.transform = transY;
    
    return offset;
}

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
